<?php
/**
 * Created by PhpStorm.
 * User: changyifan
 * Date: 2018/3/28
 * Time: 下午3:15
 */

namespace Home\Model;
use Think\Model\BaseModel;

class VideoModel extends BaseModel{

    protected $_link =  array(
        'Section' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name' => 'Section',
            'foreign_key' => 'sec_id',
            'mapping_fields' => 'cha_id,sec_name',
            'as_fields' => 'cha_id,sec_name'
        ),
        'Chapter' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name' => 'Chapter',
            'foreign_key' => 'cha_id',
            'mapping_fields' => 'tme_id',
            'as_fields' => 'tme_id'
        ),
    );
    protected $_scope = array(
        'datashow' => array(
            'where' => array('sec_id'=> ''),
        ),
    );




    public function getVideoInfoBySectionId($sec_id){

        if ($sec_id == 0) {
            $sec_id = array('like', "%%");
        }
        $video_info = $this ->scope('datashow',array('where'=>array('sec_id'=>$sec_id)))->relation(true)-> select();

        if ($video_info) {
            return $video_info;
        } else {
            return array();
        }
    }

    public function getMaxOrderBySecId($sec_id){

        $con['sec_id'] = $sec_id;
        $info = $this->where($con)->select();
        if ($info){
            $max = 1;
            foreach($info as $key => $value){
                $max = $value['order'] > $max ? $value['order'] : $max;
            }
            return $max;
        }else{
            return 0;
        }
    }
    public function getFileUUidById($vid_id){
        $uuid = $this->where(array('vid_id'=>$vid_id))->getField('vid_uuid');
        return $uuid;
    }

}